package JPrac;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class LoadDriver {

	public static void main(String[] args) {
		try{
			Class.forName("com.mysql.jdbc.Driver").newInstance();
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try{
			conn = DriverManager.getConnection("jdbc:mysql://localhost/sakila?" + "user=root&password=root");
			stmt = conn.createStatement( );
			rs = stmt.executeQuery("SELECT * FROM actor;");
			
			if(stmt.execute("SELECT * FROM actor"))
				rs = stmt.getResultSet();
				while(rs.next()){
					int id = rs.getInt("actor_id");
					String name = rs.getString("first_name")+rs.getString("last_name");
					System.out.println("Actor ID: " + id + "\tName: " + name);
				}
		}
		catch(SQLException e){
			System.out.println("SQL Exception: " + e.getMessage());
			System.out.println("SQL State: " + e.getSQLState());
			System.out.println("Vendor Error: " + e.getErrorCode());
		}
	
		finally{
			if(rs!=null){
				try{
					rs.close();
				}
				catch(SQLException se){
					
				}
				rs=null;
			}
			if(stmt!=null){
				try{
					stmt.close();
				}
				catch(SQLException se){
					
				}
				stmt=null;
			}
		}
	}
}
